/*
 * Copyright (C) 2013, Apexes Network Technology. All rights reserved.
 * 
 *        http://www.apexes.net
 * 
 */
package extfx.scene.control.samples;

import java.util.Locale;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Control;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBoxBuilder;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import extfx.scene.control.DatePicker;

/**
 *
 * @author <a href="mailto:hedyn@foxmail.com">HeDYn</a>
 */
public class DatePickerDemo extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("DatePicker Demo");
        HBox hbox = HBoxBuilder.create().build();
        hbox.setAlignment(Pos.CENTER);
        hbox.setSpacing(10);
        hbox.setPrefWidth(400);
        hbox.setMaxWidth(Control.USE_PREF_SIZE);
        
        DatePicker datePicker = new DatePicker(Locale.getDefault());
        datePicker.setDateFormat(new java.text.SimpleDateFormat("yyyy-MM-dd"));
        datePicker.getCalendarView().setTodayButtonText("今天");
        datePicker.setPromptText("请输入日期");
        //datePicker.setPrefHeight(24);
        
        final TextField field = new TextField();
        field.setPrefWidth(112);
        field.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);

        Button button = new Button("OK");
        button.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                System.out.println(field.getPrefHeight() + ", " + field.getHeight());
            }
        });
        
        hbox.getChildren().addAll(datePicker, field, button);

        Scene scene = new Scene(hbox, 400, 300);
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

            public void handle(WindowEvent event) {
                System.exit(0);
            }
        });

        stage.setScene(scene);
        stage.show();

    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
